﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace MenuGame2DXNA
{
    public class sTrailer : Scene
    {
        Video video;
        VideoPlayer player;
        Texture2D videoTexture;
        Game game;
        public override void LoadContent(Game _game)
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            game = _game;
            video = game.Content.Load<Video>("Audio/trailer");
            player = new VideoPlayer();
            player.Play(video);
        }

        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            KeyboardState kbState = Keyboard.GetState();
            if (kbState.IsKeyDown(Keys.Escape))
            {
                game.Scene = 0;
                player.Stop();
            }
           
            if (player.State == MediaState.Stopped)
            {
                game.Scene = 0;                             
            }

            
        }

        
        public override void Draw(Microsoft.Xna.Framework.GameTime gameTime, Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
       

            // Only call GetTexture if a video is playing or paused
            if (player.State != MediaState.Stopped)
                videoTexture = player.GetTexture();

            // Drawing to the rectangle will stretch the 
            // video to fill the screen
            Rectangle screen = new Rectangle(game.GraphicsDevice.Viewport.X,
               game.GraphicsDevice.Viewport.Y,
                game.GraphicsDevice.Viewport.Width,
                game.GraphicsDevice.Viewport.Height);

            // Draw the video, if we have a texture to draw.
            if (videoTexture != null)
            {
                
                spriteBatch.Draw(videoTexture, screen, Color.White);
               
            }
          
              

          
        }

      
    }
}
